<?php

/**
 * Product form.
 *
 * @package    sf_sandbox
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ProductForm extends BaseProductForm
{
  public function configure()
  {
      $session = sfContext::getInstance()->getUser();
      
      
      
      $this->widgetSchema['id_user'] = new sfWidgetFormInputHidden();
      $this->widgetSchema['price']->setAttributes(array('class' => '','size' => '35','maxlength' => '100','autocomplete' => 'off'));
      $this->widgetSchema['number_libras']->setAttributes(array('class' => '','size' => '5','autocomplete' => 'off'));
      $this->widgetSchema['price_libras']->setAttributes(array('class' => '','size' => '5','autocomplete' => 'off'));
      $this->widgetSchema['price_secure_transport']->setAttributes(array('class' => '','readonly' => true));
      $this->widgetSchema['image'] = new sfWidgetFormInputFileEditable(array(
                'label'         => 'Image',
                'file_src'      => false,
                'is_image'      => true,
                'edit_mode'     => !$this->isNew(),
                'template'      => '<div>%file%<br />%input%<br /></div>',
      ));
      
      
      $this->setDefault('id_user', $session->getAttribute('id_user_seller'));
          
      //Validators
      $this->validatorSchema['image'] = new sfImageFileValidator(array(
                'required'      => false,
                'mime_types'    => array('image/jpeg', 'image/png', 'image/gif', 'image/pjpeg'),
                'max_size'      => '600000',
                'min_height'    => '300',
                'min_width'     => '500',
                'path'          => sfConfig::get('sf_upload_dir').'/products/'.$session->getAttribute('id_user_seller'),
            ), array(
                'required'      => "La imagen principal es requerida",
                'min_width'     => "El ancho de la imagen es muy corto (mínimo es %min_width%px, tiene %width%px ).",
                'min_height'    => "La altura mínima de la imagen debe ser 300px."

      ));
      if(!$this->getObject()->isNew() && $this->getObject()->getImage())
      {
          $this->setDefault('image', '');
      }
      //Etiquetas
      $this->widgetSchema->setLabels( array(
          'id_category'     => 'Categoría',
          'id_subcategory'     => 'Sub-Categoría',
          'id_producer'     => 'Fabricante',
          'name_product'     => 'Nombre Producto',
          'price'     => 'Precio',
          'quantity'     => 'Cantidad',
          'image'     => 'Imagen',
          'description'     => 'Datos principales',
          'devasin'     => 'DEVASIN',
          'price_secure_transport'     => 'Costo del Seguro de envío',
          'number_libras'   => 'Peso / Libras',
          'price_libras'   => 'Precio X Libras'
          
      ));
      
      //Mensajes de ayuda
      $this->widgetSchema->setHelps(array(
      'image'   =>      'La imagen debe ser jpeg, jpg, png o gif<br />
                        Preferiblemente las dimensiones deben ser: 600px * 415px <br />
                        La imagen debe tener un peso máximo de: '.sfConfig::get('app_image_size_text').'<br/>',
      
      ));
      
      
      
     
  }
}
